{% extends "base.html" %}
{% block extra_src %}
	<link rel="stylesheet" href="/site_media/r_m.css" type="text/css" />
{% endblock %}

{% block script %}
<script>	$(function() {
		$( "#accordion_menu" ).accordion({
			collapsible: true,			
			active: -1,
			autoHeight: false,
		});		
		$( "#accordion_order" ).accordion({
			collapsible: true,			
			active: 0,
			autoHeight: false,
		});
		
		update();
	});
	
	function update()
	{
		url=base_url + "/restaurant_manage/update/";
		send_query(url);
		setTimeout("update();",5000);
	}
	function change_order_status(id)
	{
		url=base_url + "/order/"+id+"/change_status/";
		send_query(url, order_status_changed);
	}
	function undo_change_order_status(id)
	{
		url=base_url + "/order/"+id+"/undo_change_status/";
		send_query(url, order_status_changed);
	}
	function order_status_changed()
	{
		if (xmlhttp.readyState==4)
	  	{
	  		// 4 = "loaded"
	  		if (xmlhttp.status==200)
	    	{
	    		// 200 = "OK"
	    		r = xmlhttp.responseText;
	    		if(r == "Error")
	    		{
	    			alert("修改订单状态时发生未知错误。");
	    		}
	    		window.location.reload();
	    	}
	  		else
	    	{
	    		//alert("Problem retrieving data:" + xmlhttp.statusText);
	   	 	}
	  	}
	}
</script>
{% endblock %}

{% block head %}{{restaurant.name}}{% endblock %}

{% block menu%}

{% endblock %}

{% block content %}
  {% if restaurant.username %}
    {% if errors %}
    <p style="color: red;">
            Please correct the error{{ errors }} below.
    </p>
    {% endif %}    
    
    <ul>
    {% for o in orders %}
    	<li>
    		<p>用户名字：{{o.customer.name}}</p>
    		<p>送餐地址：{{o.customer.get_address}}</p>
    		<p>联系电话：{{o.customer.phone}}</p>
    		<p>用户下单时间：{{o.get_time1}}</p>
    		<p>餐馆确认时间：{{o.get_time2}}</p>
    		<p>开始配送时间：{{o.get_time3}}</p>
    		<p>完成时间：{{o.get_time4}}</p>
    		<p>已点餐品：
    			<ul>
    			{% for i in o.get_items%}
    				<li>{{i.item.name}},{{i.item.price}},{{i.count}},{{i.get_total}},{{i.item.description}} </li>
    			{% endfor %}
    			</ul>
    		</p>
    		<p>订单状态：{{o.get_status}} 
    			{% if o.status <= 3 %}
    			<input type='button' value='{{o.get_button_value}}' onclick='change_order_status({{o.id}});'>
    			{% endif %}
    			{% if o.status > 1 %}
    			<input type='button' value='撤销' onclick='undo_change_order_status({{o.id}});'>
    			{% endif %}
    		</p>
    	</li>
    {% endfor %}
    </ul>
  {% else %}
    <p>You are not a restaurant user.</p>
  {% endif %}
{% endblock %}
{% block sidebar%}
  <div id="order_controller" class="div_controller">
  <h2><a class="a_controller" href="/restaurant_manage">订单查看</a></h2>
  <div id="accordion_order">
	<h3><a href="#">Orders in today</a></h3>
	<div>
		<ul>
		    <li>By time</li>
		    <li>By status</li>
		    <li>By xxx</li>
		</ul>
	</div>
	<h3><a href="#">Orders in history</a></h3>
	<div>
		<ul>
		    <li>By time</li>
		    <li>By status</li>
		    <li>By xxx</li>
		</ul>
	</div>
  </div>
  </div>
  
  <div id="menu_controller" class="div_controller">
  <h2><a class="a_controller" href="/restaurant_manage/menu">菜单管理</a></h2>
  <div id="accordion_menu">
	<h3><a class="" href="#">添加菜单类别</a></h3>
	<div>
		<form method="post" action="">
  			{% csrf_token %}
  			{{ form_ac.as_p }}
  			<p><input type="submit" value="提交" class="submit"/></p>
  			<input type="hidden" id="form_ac" name="form_ac" value="form_ac">
		</form>
	</div>
	<h3><a href="#">编辑菜单类别</a></h3>
	<div>
		<form method="post" action="">
  			{% csrf_token %}
  			{{ form_ec.as_p }}
  			<p><input type="submit" value="提交" class="submit"/></p>
  			<input type="hidden" id="form_ec" name="form_ec" value="form_ec">
		</form>
	</div>
	<h3><a href="#">添加菜品</a></h3>
	<div>
		<form method="post" action="">
  			{% csrf_token %}
  			{{ form_ai.as_p }}
  			<p><input type="submit" value="提交" class="submit"/></p>
  			<input type="hidden" id="form_ai" name="form_ai" value="form_ai">
		</form>
	</div>
	<h3><a href="#">编辑菜品</a></h3>
	<div>
		<form method="post" action="">
  			{% csrf_token %}
  			{{ form_ei.as_p }}
  			<p><input type="submit" value="提交" class="submit"/></p>
  			<input type="hidden" id="form_ei" name="form_ei" value="form_ei">
		</form>
	</div>
  </div>
  </div>
  
  
  
  
{% endblock%}